﻿namespace Pay.Core
{
	/// <summary>
	/// 服务监控
	/// </summary>
	public class HealthMiddleware
	{
		private readonly RequestDelegate _next;

		/// <summary>
		/// ctor
		/// </summary>
		public HealthMiddleware(RequestDelegate next)
		{
			_next = next;
		}

		/// <summary>
		/// invoke
		/// </summary>
		public async Task Invoke(HttpContext httpContext)
		{
			if (httpContext.Request.Path.HasValue && "/health".Equals(httpContext.Request.Path.Value.TrimEnd('/').ToLower()))
			{
				await httpContext.Response.WriteAsync(DateTimeOffset.Now.ToString("G"));
				return;
			}

			await _next(httpContext);
		}
	}
}
